<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<jsp:include page="/includes/top.jsp"></jsp:include>
<div class="page-header">
	<h1></h1>
</div>
<!-- /.page-header -->
<div class="row">
	<div class="col-xs-12">
		<form class="form-horizontal" id="uiform">
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">旧密码</label>
				<div class="col-sm-4">
					<div class="clearfix input-icon input-icon-right">
						<input type="text" name="users.oldPassword" class="form-control"
							placeholder="旧密码" id="txtOldPassword" />
					</div>
				</div>
			</div>
			<div class="form-group edithid">
				<label class="col-sm-3 control-label no-padding-right">新密码</label>
				<div class="col-sm-4">
					<div class="clearfix input-icon input-icon-right">
						<input type="password" name="users.userPassword"
							class="form-control" placeholder="新密码" />
					</div>
				</div>
			</div>
			<div class="form-group edithid">
				<label class="col-sm-3 control-label no-padding-right">确认密码</label>
				<div class="col-sm-4">
					<div class="clearfix input-icon input-icon-right">
						<input type="password" name="users.confirmPassword"
							class="form-control" placeholder="确认密码" />
					</div>
				</div>
			</div>
			<div class="clearfix form-actions">
				<div class="col-md-offset-3 col-md-9">
					<button class="btn btn-info" type="button" id="save">
						<i class="icon-ok"></i> 保存
					</button>

					&nbsp; &nbsp; &nbsp;
					<button class="btn" type="reset" id="back">
						<i class="icon-undo"></i> 取消
					</button>
				</div>
			</div>
		</form>
	</div>
	<!-- /.col -->
</div>
<jsp:include page="/includes/bottom.jsp"></jsp:include>

<script src="assets/js/bootstrapValidator.min.js"></script>

<script type="text/javascript">

	function savafrom() {
		$("#save").click(function() {
			$("#uiform").bootstrapValidator("validate");
			if ($("#uiform").data("bootstrapValidator").isValid()) {
				var dataMap = $("#uiform").serializeArray();
				$.ajax({
					type : "post",
					url : "updatePass",
					data : dataMap,
					dataType : "json",
					success : function(data) {
						alert("密码修改成功！");
					}
				});
			}
		});
	}
	$(document).ready(function() {
		savafrom();
		validator();
		$("#back").click(function() {
			window.history.back();
		});
	});

	function validator() {
		$("#uiform").bootstrapValidator({
			feedbackIcons : {
				valid : 'icon-ok-sign',
				invalid : 'icon-remove-sign',
				validating : 'icon-refresh'
			},
			fields : {
				'users.oldPassword' : {
					validators : {
						notEmpty : {
							message : '旧密码，不能为空！'
						},
						stringLength : {
							min : 5,
							max : 30,
							message : '旧密码长度必须是5-30字符！'
						},
						regexp : {
							regexp : /^[a-zA-Z0-9_\.]+$/,
							message : '旧密码只能输入数字或字母！'
						},
						remote : {
							url : 'checkPass',
							message : '旧密码不正确，请重新输入！',
							data : {
								"users.oldPassword" : $("#txtOldPassword").val()
							}
						}
					}
				},
				'users.userPassword' : {
					validators : {
						notEmpty : {
							message : '新密码，不能为空！'
						},
						stringLength : {
							min : 5,
							max : 30,
							message : '新密码长度必须是5-30字符！'
						},
						regexp : {
							regexp : /^[a-zA-Z0-9_\.]+$/,
							message : '新密码只能输入数字或字母！'
						}
					}
				},
				'users.confirmPassword' : {
					validators : {
						notEmpty : {
							message : '确认密码，不能为空！'
						},
						identical : {
							field : 'users.userPassword',
							message : '两次输入密码不一致！'
						},
						stringLength : {
							min : 5,
							max : 30,
							message : '确认密码长度必须是5-30字符！'
						},
						regexp : {
							regexp : /^[a-zA-Z0-9_\.]+$/,
							message : '确认密码只能输入数字或字母！'
						}
					}
				}
			}
		});
	}
</script>